package com.firefighting.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.firefighting.pdfEntity.FirstMaintenance;
import com.firefighting.pdfEntity.SecondMaintenance;
import com.firefighting.pdfEntity.TaskItem;
import com.firefighting.pdfEntity.ThirdMaintenance;
import com.firefighting.util.*;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BarcodeQRCode;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;


public class Cover {
	public static final String RESOURCE = "resources/js/buttons.js";
	public static final String[] TIME = { "月报", "季报", "年报"};
//	public static Document document = new Document(PageSize.A4, 50, 50, 50, 50); 
	private String[][] TableContent = new String[][]{
		{"序号","单项名称","维护保养情况汇总"},
		{"1","消防供电配电","□ 符合"+" □ 不符合"+" □ 无"},{"2","火灾报警系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"3","电气火灾监控系统","□ 符合"+" □ 不符合"+" □ 无"},{"4","消防供水设施","□ 符合"+" □ 不符合"+" □ 无"}
		,{"5","消火栓（消防炮）\r\n"+"灭火系统","□ 符合"+" □ 不符合"+" □ 无"},{"6","自动喷水灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"7","泡沫灭火系统","□ 符合"+" □ 不符合"+" □ 无"},{"8","气体灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"9","机械加压送风系统","□ 符合"+" □ 不符合"+" □ 无"},{"10","机械排烟系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"11","集中控制应急照明系统\r\n"+"及疏散指示标志","□ 符合"+" □ 不符合"+" □ 无"}
		,{"12","应急广播系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"13","消防专用电话","□ 符合"+" □ 不符合"+" □ 无"}
		,{"14","防火分隔","□ 符合"+" □ 不符合"+" □ 无"}
		,{"15","消防电梯","□ 符合"+" □ 不符合"+" □ 无"}
		,{"16","细水雾灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"17","干粉灭火系统","□ 符合"+" □ 不符合"+" □ 无"}
		,{"18","灭火器","□ 符合"+" □ 不符合"+" □ 无"}
		,{"19","其他设施","□ 符合"+" □ 不符合"+" □ 无"}
		,{"20","主要消防设施标识","□ 符合"+" □ 不符合"+" □ 无"}
	};
	
	
	public String CreatCover(PdfWriter writer,String fileroot,String pdfname,Document document,String contractid, String end_time,String start_time,String time) throws IOException, DocumentException, SQLException, ParseException{

//		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
//		OutputStream pdfFileOutputStream = new FileOutputStream(new File(filename));
//		PdfWriter writer=PdfWriter.getInstance(document,pdfFileOutputStream);
//		document.open();
        // step 3

        BaseFont bfChinese = BaseFont.createFont("C:/Windows//Fonts//SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
       
        String myString = "http://47.106.213.57:8080/report/"+pdfname;  
        BarcodeQRCode qrcode = new BarcodeQRCode(myString.trim(), 1, 1, null);  
        Image qrcodeImage = qrcode.getImage();  
        qrcodeImage.setAbsolutePosition(10,720);  
        qrcodeImage.scalePercent(300);
        document.add(qrcodeImage);  
        
        //封面第一行
        Font titlefont = new Font(bfChinese, 21, Font.NORMAL);
        Paragraph covertitle = new Paragraph("建 筑 消 防 设 施 维 护 保 养",titlefont);
        covertitle.setAlignment(1);
        covertitle.setSpacingBefore(60);
        covertitle.setSpacingAfter(50);
        document.add(covertitle);
        System.out.println("建 筑 消 防 设 施 维 护 保 养");
        
        //封面第二行
        Font titlefont2 = new Font(bfChinese, 40, Font.NORMAL);
        Paragraph covertitle2 = new Paragraph("报   告   书",titlefont2);
        covertitle2.setAlignment(1);
        covertitle2.setSpacingBefore(30);
        covertitle2.setSpacingAfter(10);
        document.add(covertitle2);
        
        
        //增加月、季、年
        Font contentfont = new Font(bfChinese, 16, Font.NORMAL);
        Font timefont = new Font(bfChinese, 18, Font.NORMAL);
        Paragraph titletime = new Paragraph("("+time+" 报"+")",timefont);
        titletime.setAlignment(1);
        titletime.setSpacingBefore(10);
        titletime.setSpacingAfter(50);
        document.add(titletime);
//        writer.addJavaScript(Utilities.readFileToString(RESOURCE));
//        PdfContentByte canvas = writer.getDirectContent();
//		Rectangle rect;
//        PdfFormField field;
//        PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
//        radiogroup.setFieldName("time");
//        RadioCheckField radio;
//        for (int i = 0; i < TIME.length; i++) {
//            rect = new Rectangle(260, 559 - i * 40, 280, 541 - i * 40);
//            radio = new RadioCheckField(writer, rect, null, TIME[i]);
//            radio.setBorderColor(GrayColor.GRAYBLACK);
//            radio.setBackgroundColor(GrayColor.GRAYWHITE);
//            radio.setCheckType(RadioCheckField.TYPE_CHECK);
//            field = radio.getRadioField();
//            radiogroup.addKid(field);
//            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
//                new Phrase(TIME[i], contentfont), 290, 544 - i * 40, 0);
//        }
//        writer.addAnnotation(radiogroup);

		

        
        //增加项目名称    
        
        Statement stmt = DBUtil.getConnection().createStatement();
        ResultSet rs = stmt.executeQuery("select project_name from contract where ID='"+contractid+"'");
        while(rs.next()){
    	    String str=rs.getString("project_name");
            Paragraph content = new Paragraph("项   目   名   称:"+" ",contentfont);
            Chunk underline = new Chunk(str,contentfont);
            underline.setUnderline(0.1f, -2f);
            content.add(underline);     
            content.setAlignment(0);
            content.setSpacingBefore(100);
            content.setIndentationLeft(90);
            content.setSpacingAfter(10);
            document.add(content);
        }
        System.out.println("project_name");  
        //增加委托单位
        ResultSet rs1 = stmt.executeQuery("select name from proprietor where id=(select proprietor_id from contract where ID='"+contractid+"')");
        while(rs1.next()) {
    	   
    	    String strname = rs1.getString("name");
            Paragraph content1 = new Paragraph("委   托   单   位:"+" ",contentfont);
            Chunk underline1 = new Chunk(strname,contentfont);
            underline1.setUnderline(0.1f, -2f); //设置下划线厚度
            content1.add(underline1);     
            content1.setAlignment(0);
            content1.setSpacingBefore(20);  //设置行前间距
            content1.setIndentationLeft(90);  //设置缩进
            content1.setSpacingAfter(10);
            document.add(content1);
        }
        System.out.println("委   托   单   位");  
       
        //增加维护保养机构名称
        ResultSet rs2 = stmt.executeQuery("select name from enterprise where id=(select maintenance_enterprise_id from contract where ID='"+contractid+"')");
        while(rs2.next()) {
    	   
    	    String strinstitutions = rs2.getString("name");
            Paragraph content = new Paragraph("维护保养机构名称 :"+" ",contentfont);
            Chunk underline = new Chunk(strinstitutions,contentfont);
            underline.setUnderline(0.1f, -2f); //设置下划线厚度
            content.add(underline);     
            content.setAlignment(0);
            content.setSpacingBefore(20);  //设置行前间距
            content.setIndentationLeft(90);  //设置缩进
            content.setSpacingAfter(10);
            document.add(content);
        }
        System.out.println("维护保养机构名称 ");
       
        //增加维护保养机构资质
        ResultSet rs3 = stmt.executeQuery("select qualification from enterprise where id=(select maintenance_enterprise_id from contract where ID='"+contractid+"')");
        while(rs3.next()) {
    	   
    	    String straptitude = rs3.getString("qualification");
            Paragraph content = new Paragraph("维护保养机构资质 :"+" ",contentfont);
            Chunk underline = new Chunk(straptitude,contentfont);
            underline.setUnderline(0.1f, -2f); //设置下划线厚度
            content.add(underline);     
            content.setAlignment(0);
            content.setSpacingBefore(20);  //设置行前间距
            content.setIndentationLeft(90);  //设置缩进
            content.setSpacingAfter(10);
            document.add(content);
        }
        
        //增加报告日期
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = sdf.format(d);
        Paragraph content = new Paragraph("报   告   日   期:"+" ",contentfont);
        Chunk underline = new Chunk(dateNowStr,contentfont);
        underline.setUnderline(0.1f, -2f); //设置下划线厚度
        content.add(underline);   
        content.setAlignment(0);
        content.setSpacingBefore(20);  //设置行前间距
        content.setIndentationLeft(90);  //设置缩进
        content.setSpacingAfter(10);
        document.add(content);

        //增加说明
        document.newPage();
        Paragraph illustratetitle = new Paragraph("说  明",titlefont);
        illustratetitle.setAlignment(1);
        illustratetitle.setSpacingBefore(40);
        illustratetitle.setSpacingAfter(20);
        document.add(illustratetitle);
        //增加说明内容
        Font illustratefont = new Font(bfChinese, 14, Font.NORMAL);
        Paragraph illustrate1 = new Paragraph("    1、本报告书统一使用国际标准A4型纸，由各建筑消防设施维护保养机构按照规定的式样制作，"
        		+ "封面、封底采用200g铜版纸印刷，其他页电脑打印，装订成册。报告书设定的栏目应逐项填写完整、准确；"
        		+ "不需填写的，应在空白处填写“无”。",illustratefont);
        illustrate1.setAlignment(0);        
        illustrate1.setSpacingAfter(5);
        document.add(illustrate1);
        
        Paragraph illustrate2 = new Paragraph("    2、本报告书包含封面、《建筑消防设施维护保养情况表》、《建筑消防设施" + 
        		"汇总表》、《建筑消防设施维护保养表（月/季/年度）》及封底。每份报告书应按 "+ 
        		"顺序编写页码，在“共 页第 "+ 
        		"页”处分别填写总页数、页码，如：“共6页第2页”。",illustratefont);
        illustrate2.setAlignment(0);        
        illustrate2.setSpacingAfter(5);
        document.add(illustrate2);
        System.out.println("demostration");
        
        Paragraph illustrate3 = new Paragraph("    3、本报告书中的《建筑消防设施维护保养表》的内容应与维保现场填写的《" + 
        		"建筑消防设施维护保养记录表》内容一致，由技术负责人、项目负责人、编制人审" + 
        		"核确认，并加盖建筑消防设施维护保养机构印章、骑缝章。",illustratefont);
        illustrate3.setAlignment(0);        
        illustrate3.setSpacingAfter(5);
        document.add(illustrate3);
        
        Paragraph illustrate4 = new Paragraph("    4、报告书中的“□”，表示可供选择，在选中内容前的“□”内画√。",illustratefont);
        illustrate4.setAlignment(0);        
        illustrate4.setSpacingAfter(5);
        document.add(illustrate4);
        
        Paragraph illustrate5 = new Paragraph("    5、《建筑消防设施维护保养表（月/季/年度）》内的实测记录的应当载明所" + 
        		"检查测试的设施所在具体位置、名称及编号、型号、数量等，并客观记录其运行的" + 
        		"具体数据（值）或状态，同时将实测记录与“测试方法和要求”对比判定，在符合" + 
        		"和不符合前的“□”内画√。",illustratefont);
        illustrate5.setAlignment(0);        
        illustrate5.setSpacingAfter(5);
        document.add(illustrate5);
        
        Paragraph illustrate6 = new Paragraph("    6、应在《建筑消防设施报告汇总表》的维护保养情况栏内要写明《建筑消防" + 
        		"设施维护保养表》内不符合标准要求的维保项目和内容的编号及不符合情况描述。",illustratefont);
        illustrate6.setAlignment(0);        
        illustrate6.setSpacingAfter(5);
        document.add(illustrate6);
        
        Paragraph illustrate7 = new Paragraph("    7、《建筑消防设施维护保养情况表》中“维护保养单位意见”栏应载明维护" + 
        		"保养基本情况、各维保项目工作情况、记录不符合要求项存在的具体问题，并对维" + 
        		"护保养设施完好情况综合判定，提出处理意见或建议。",illustratefont);
        illustrate7.setAlignment(0);        
        illustrate7.setSpacingAfter(5);
        document.add(illustrate7);
        
        Paragraph illustrate8 = new Paragraph("    8、建筑消防设施维护保养机构应如实填写各项内容，对提交材料的真实性、" + 
        		"完整性负责，不得虚构、伪造或编造事实，否则将承担相应的法律后果。",illustratefont);
        illustrate8.setAlignment(0);        
        illustrate8.setSpacingAfter(5);
        document.add(illustrate8);
        
        Paragraph illustrate9 = new Paragraph("    9、本报告书一式三份，一份本机构存档，一份送委托单位，一份送公安机关" + 
        		"消防机构备案。",illustratefont);
        illustrate9.setAlignment(0);        
        illustrate9.setSpacingAfter(5);
        document.add(illustrate9);
        
        //建筑消防设施维护保养情况表
        document.newPage();
        Paragraph situationtitle = new Paragraph("建筑消防设施维护保养情况表",titlefont);
        situationtitle.setAlignment(1);
        situationtitle.setSpacingBefore(40);
        situationtitle.setSpacingAfter(20);
        document.add(situationtitle);
        
        //添加页脚
        PdfContentByte headAndFootPdfContent = writer.getDirectContent();
        headAndFootPdfContent.saveState();
        headAndFootPdfContent.beginText();
      //设置中文
        headAndFootPdfContent.setFontAndSize(bfChinese, 8);
        //文档页脚信息设置  
        float y = document.bottom(-20);
        float y1 = document.bottom(-35);
        //页脚信息左面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_LEFT, "项目负责人：          "+"     技术负责人：          "+"     编制人：          ", document.left() , y, 0);
        //页脚信息右面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_RIGHT, "共    页     第    页 ", document.right(), y, 0);     
        headAndFootPdfContent.endText();
        headAndFootPdfContent.restoreState();
        
        
        
        //保养情况表格
        Font tablefont = new Font(bfChinese, 12, Font.NORMAL);
        PdfPTable t = new PdfPTable(13);  
        t.setWidthPercentage(100);
        int width[] = { 40, 30,30,30, 50, 50, 50, 50, 50, 50,50,50,50 };  
        t.setWidths(width); 
        t.setPaddingTop(1);

  
        PdfPCell c1 = new PdfPCell(new Phrase("项\r\n" + 
        		"目\r\n" + 
        		"概\r\n" + 
        		"况\r\n", tablefont));
        c1.setLeading(2,(float) 1.3);
        c1.setRowspan(3); 
        c1.setColspan(1);
        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1);  
  
        c1 = new PdfPCell(new Phrase("场 所 名 称", tablefont));  
        c1.setRowspan(1);
        c1.setColspan(3);
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1);  
        System.out.println("保养situation ");
          
  
        
        
        ResultSet rscell1 = stmt.executeQuery("select building_name from building where contract_id='"+contractid+"'");
        while(rscell1.next()){
    	    String str=rscell1.getString("building_name");
    	    c1 = new PdfPCell(new Phrase(str, tablefont));  
        }
        c1.setRowspan(1);
        c1.setColspan(9); 
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1);  
                
        c1 = new PdfPCell(new Phrase("地     址", tablefont));  
        c1.setRowspan(1);
        c1.setColspan(3);
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1); 
         
        
        ResultSet rscell2 = stmt.executeQuery("select province,city,district,address from contract where Id='"+contractid+"'");
        while(rscell2.next()){
    	    String str=rscell2.getString("province")+rscell2.getString("city")+rscell2.getString("district")+rscell2.getString("address");
    	    c1 = new PdfPCell(new Phrase(str, tablefont));  
        }
        c1.setRowspan(1);
        c1.setColspan(9);
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1); 
        
        c1 = new PdfPCell(new Phrase("负 责 人", tablefont));  
        c1.setRowspan(1);
        c1.setColspan(3);
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1);  
                 
        ResultSet rscell3 = stmt.executeQuery("select name from user_basic_info where login_id=(select project_leader_account from contract where Id='"+contractid+"')");
        while(rscell3.next()){
    	    String str=rscell3.getString("name");
    	    c1 = new PdfPCell(new Phrase(str, tablefont));  
        }
        c1.setRowspan(1);
        c1.setColspan(3);
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1);  
        
        c1 = new PdfPCell(new Phrase("联系方式", tablefont));  
        c1.setRowspan(1);
        c1.setColspan(3); 
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1);  

        ResultSet rscell4 = stmt.executeQuery("select phone_number from user_basic_info where login_id=(select project_leader_account from contract where Id='"+contractid+"')");
        while(rscell4.next()){
    	    String str=rscell4.getString("phone_number");
    	    c1 = new PdfPCell(new Phrase(str, tablefont));  
        }
        c1.setRowspan(1);
        c1.setColspan(3);
        c1.setLeading(2,(float) 1.3);
//        c1.setHorizontalAlignment(c1.ALIGN_CENTER);
        c1.setVerticalAlignment(c1.ALIGN_MIDDLE);
        t.addCell(c1); 
        
        PdfPCell c2 = new PdfPCell(new Phrase("建\r\n" + 
        		"筑\r\n" + 
        		"消\r\n" + 
        		"防\r\n" + 
        		"设\r\n" + 
        		"施\r\n" + 
        		"概\r\n" + 
        		"况", tablefont));
        c2.setLeading(2,(float) 1.3);
        c2.setRowspan(10); 
        c2.setColspan(1);
        c2.setHorizontalAlignment(c2.ALIGN_CENTER);
        c2.setVerticalAlignment(c2.ALIGN_MIDDLE);
        t.addCell(c2);
        
        c2 = new PdfPCell(new Phrase(" \r\n" +
        		"维\r\n" +         
        		"保\r\n" +
        		"建\r\n" +
        		"筑\r\n" +
        		"物\r\n" +
        		"概\r\n" +
        		"况\r\n"+
        		" \r\n", tablefont)); 
        c2.setLeading(2,(float) 1.3);
        c2.setRowspan(7);
        c2.setColspan(3);
        c2.setHorizontalAlignment(c2.ALIGN_CENTER);
        c2.setVerticalAlignment(c2.ALIGN_MIDDLE);
        t.addCell(c2);

        ResultSet rscell5 = stmt.executeQuery("select building_area,Overground_area,upground_area,Overground_layer,Underground_layer,Building_height from building where contract_id='"+contractid+"'");
        while(rscell5.next()){
    	    double str=rscell5.getDouble("building_area");
    	    int str1=rscell5.getInt("Overground_layer");
    	    double str2=rscell5.getDouble("Overground_area");
    	    int str3=rscell5.getInt("underground_layer");
    	    double str4=rscell5.getDouble("Upground_area");
    	    int str5=rscell5.getInt("Building_height");   	    
    	    c2 = new PdfPCell(new Phrase("  总建筑面积"+str+"平米。"+"地上"+str1+"层，"+str2+"平米。"+"地下"+str3+"层，"+str4+"平米。建筑高度"+str5+"米。", tablefont));  
        }
        c2.setLeading(2, (float) 1.5);
        c2.setRowspan(7);
        c2.setColspan(9); 
        c2.setPaddingBottom(100);
//        c2.setHorizontalAlignment(c2.ALIGN_CENTER);
//        c2.setVerticalAlignment(c2.ALIGN_MIDDLE);
        t.addCell(c2);
        
        c2 = new PdfPCell(new Phrase("重\r\n" + 
        		"点\r\n" + 
        		"部\r\n" + 
        		"位", tablefont));
        c2.setLeading(2,(float) 1.3);
        c2.setRowspan(3);
        c2.setColspan(3);
        c2.setHorizontalAlignment(c2.ALIGN_CENTER);
        c2.setVerticalAlignment(c2.ALIGN_MIDDLE);
        t.addCell(c2);
        


        c2 = new PdfPCell(new Phrase("  □消防控制室设置位置：\r\n" + 
        		"  □消防水箱设置位置：         容量：  m3\r\n" + 
        		"  □消防水池设置位置：         容量：  m3", tablefont)); 
        c2.setLeading(2,(float) 1.5);
        c2.setRowspan(3);
        c2.setColspan(9);
        c2.setPaddingBottom(50);
//        c2.setHorizontalAlignment(c2.ALIGN_CENTER);
        c2.setVerticalAlignment(c2.ALIGN_MIDDLE);
        t.addCell(c2);
        
        PdfPCell c3 = new PdfPCell(new Phrase("维\r\n" + 
        		"护\r\n" + 
        		"保\r\n" + 
        		"养\r\n" + 
        		"概\r\n" + 
        		"况", tablefont));
        c3.setLeading(2,(float) 1.3);
        c3.setRowspan(20); 
        c3.setColspan(1);
        c3.setHorizontalAlignment(c3.ALIGN_CENTER);
        c3.setVerticalAlignment(c3.ALIGN_MIDDLE);
        t.addCell(c3);
        
        c3 = new PdfPCell(new Phrase("维\r\n" + 
        		"护\r\n" + 
        		"保\r\n" + 
        		"养\r\n" + 
        		"项\r\n" + 
        		"目\r\n" + 
        		"范\r\n" + 
        		"围", tablefont));
        c3.setRowspan(20);
        c3.setLeading(2,(float) 1.3);
        c3.setColspan(3);
        c3.setHorizontalAlignment(c3.ALIGN_CENTER);
        c3.setVerticalAlignment(c3.ALIGN_MIDDLE);
        t.addCell(c3);
        
        
        c3 = new PdfPCell();
        c3.setRowspan(20);
        c3.setColspan(9);
        ResultSet rs4 = stmt.executeQuery("select * from first_maintenance_project as d where d.Id in (select distinct(c.Id) from first_maintenance_project as c ,"
        + "second_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and a.father_id=c.Id and b.contract_id='"+contractid+"') order by d.Id");
        int i=1;
        String str = null;
        String str1 = " ";
        Phrase content1 = new Phrase();
        while(rs4.next()) {
        	str = rs4.getString("Name");
        	str1=str1+ "\r\n"+i+"、"+str; 
        	
//        	c3.setRowspan(3); 
//            c3.setColspan(5);

            i++;
        }
        content1 = new Phrase(str1,tablefont);
        c3.setLeading(2,(float) 1.3);
        c3.setPaddingBottom(20);
        c3.setPaddingLeft(20);
        c3.setPhrase(content1);
        c3.setHorizontalAlignment(c3.ALIGN_LEFT);

        t.addCell(c3);               
        document.add(t);
        
        
        //增加建筑消防设施维护保养情况表
        document.newPage();
        Paragraph title = new Paragraph("建筑消防设施维护保养情况表",titlefont);
        title.setAlignment(1);
        title.setSpacingBefore(40);
        title.setSpacingAfter(20);
        document.add(title);
        
        //添加页脚
        headAndFootPdfContent.saveState();
        headAndFootPdfContent.beginText();
      //设置中文
        headAndFootPdfContent.setFontAndSize(bfChinese, 8);
        //页脚信息左面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_LEFT, "项目负责人：          "+"     技术负责人：          "+"     编制人：          ", document.left() , y, 0);
        //页脚信息右面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_RIGHT, "共    页     第    页 ", document.right(), y, 0);     
        headAndFootPdfContent.endText();
        headAndFootPdfContent.restoreState();
        
        //表格
        PdfPTable t1 = new PdfPTable(13);  
        t1.setWidthPercentage(100);
        int width1[] = { 40, 30,30,30, 50, 50, 50, 50, 50, 50,50,50,50 };  
        t1.setWidths(width1); 
        t1.setPaddingTop(1);

  
        PdfPCell c4 = new PdfPCell(new Phrase("维\r\n" + 
        		"护\r\n" + 
        		"保\r\n" + 
        		"养\r\n" + 
        		"单\r\n" + 
        		"位\r\n" + 
        		"意\r\n" + 
        		"见", tablefont));
        c4.setLeading(2,(float) 1.3);
        c4.setRowspan(12); 
        c4.setColspan(1);
        c4.setHorizontalAlignment(c4.ALIGN_CENTER);
//        c4.setVerticalAlignment(c4.ALIGN_MIDDLE);
        t1.addCell(c4); 
        
        c4 = new PdfPCell(new Phrase( "（维护保养机构印章）\r\n" + 
        		"年    月    日", tablefont));
        c4.setRowspan(12); 
        c4.setColspan(12);
//        c4.setHorizontalAlignment(c4.ALIGN_CENTER);
        c4.setVerticalAlignment(c4.ALIGN_BOTTOM);
        c4.setHorizontalAlignment(c4.ALIGN_RIGHT);
        c4.setPaddingBottom(10);
        c4.setLeading(2,(float) 1.3);
        c4.setPaddingTop(500);
        c4.setPaddingRight(70);
        t1.addCell(c4);
        
        document.add(t1);
        
      //增加建筑消防设施报告汇总表
        document.newPage();
        Paragraph title1 = new Paragraph("建筑消防设施报告汇总表",titlefont);
        title1.setAlignment(1);
        title1.setSpacingBefore(40);
        title1.setSpacingAfter(20);
        document.add(title1);
        
      //添加页脚
        headAndFootPdfContent.saveState();
        headAndFootPdfContent.beginText();
      //设置中文
        headAndFootPdfContent.setFontAndSize(bfChinese, 8);
        //页脚信息左面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_LEFT, "项目负责人：          "+"     技术负责人：          "+"     编制人：          ", document.left() , y, 0);
        //页脚信息右面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_RIGHT, "共    页     第    页 ", document.right(), y, 0);     
        headAndFootPdfContent.endText();
        headAndFootPdfContent.restoreState();
        
      //表格
        PdfPTable t2 = new PdfPTable(TableContent[0].length); 
//        PdfPTable t2 = new PdfPTable(13);  
        t2.setWidthPercentage(100);
        int width2[]= {100,250,400}; 
        t2.setWidths(width2); 
        t2.setPaddingTop(1);
        t2.getDefaultCell().setMinimumHeight(100);
        PdfPCell pdfTableContentCell = new PdfPCell();
        pdfTableContentCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pdfTableContentCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        for(int j = 0;j < 21;j++){
            for(String tableContentInfo : TableContent[j]){
            	pdfTableContentCell.setPhrase(new Paragraph(tableContentInfo, tablefont));
            	pdfTableContentCell.setMinimumHeight(40);  
            	t2.addCell(pdfTableContentCell);
            }
        }
    
        document.add(t2);
        
        document.add(new Paragraph(" "));
        PdfPTable t3 = new PdfPTable(13);  
        t3.setWidthPercentage(100);
        int width3[] = { 40, 30,30,30, 50, 50, 50, 50, 50, 50,50,50,50 };  
        t3.setWidths(width3); 
        t3.setPaddingTop(1);
        
        PdfPCell c6 = new PdfPCell(new Phrase("维护保养期限：", tablefont));
        c6.setLeading(2,(float) 1.3);
        c6.setRowspan(3); 
        c6.setColspan(4);
        c6.setBorder(1);
        c6.setHorizontalAlignment(c6.ALIGN_CENTER);
        c6.setVerticalAlignment(c6.ALIGN_MIDDLE);
        c6.setMinimumHeight(30);
        t3.addCell(c6); 
        
        
        ResultSet rs5 = stmt.executeQuery("select sign_date from contract where Id='"+contractid+"'");
        while(rs5.next()) {
        	String str2 = rs5.getString("sign_date");
        	SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        	java.util.Date date_util = sdf1.parse(str2); 
        	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
        	String datestr = sdf2.format(date_util);
        	c6 = new PdfPCell(new Phrase(datestr, tablefont));
        }
        c6.setLeading(2,(float) 1.3);
        c6.setRowspan(3); 
        c6.setColspan(3);
        c6.setBorder(1);
        c6.setMinimumHeight(30);
        c6.setHorizontalAlignment(c6.ALIGN_CENTER);
        c6.setVerticalAlignment(c6.ALIGN_MIDDLE);
        t3.addCell(c6);
        
        
        c6 = new PdfPCell(new Phrase("—", tablefont));
        c6.setLeading(2,(float) 1.3);
        c6.setRowspan(3); 
        c6.setColspan(3);
        c6.setBorder(1);
        c6.setMinimumHeight(30);
        c6.setHorizontalAlignment(c6.ALIGN_CENTER);
        c6.setVerticalAlignment(c6.ALIGN_MIDDLE);
        t3.addCell(c6);
        
        
        ResultSet rs6 = stmt.executeQuery("select end_date from contract where Id='"+contractid+"'");
        while(rs6.next()) {
        	String str2 = rs6.getString("end_date");
        	SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        	java.util.Date date_util = sdf1.parse(str2); 
        	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
        	String datestr = sdf2.format(date_util);
        	c6 = new PdfPCell(new Phrase(datestr, tablefont));
        }
        c6.setLeading(2,(float) 1.3);
        c6.setRowspan(3); 
        c6.setColspan(3);
        c6.setBorder(1);
        c6.setMinimumHeight(30);
        c6.setHorizontalAlignment(c6.ALIGN_CENTER);
        c6.setVerticalAlignment(c6.ALIGN_MIDDLE);
        t3.addCell(c6);
        document.add(t3);
        
        PdfPTable t4 = new PdfPTable(13);  
        t4.setWidthPercentage(100);
        int width4[] = { 40, 30,30,30, 50, 50, 50, 50, 50, 50,50,50,50 };  
        t4.setWidths(width4); 
        t4.setPaddingTop(1);
        
        PdfPCell c7 = new PdfPCell(new Phrase("项目负责人：", tablefont));
        c7.setLeading(2,(float) 1.3);
        c7.setRowspan(3); 
        c7.setColspan(4);
        c7.setBorder(2);
        c7.setMinimumHeight(30);
        c7.setHorizontalAlignment(c7.ALIGN_CENTER);
        c7.setVerticalAlignment(c7.ALIGN_MIDDLE);
        t4.addCell(c7); 

        ResultSet rs7 = stmt.executeQuery("select name from user_basic_info where login_id=(select project_leader_account from contract where Id='"+contractid+"')");
        while(rs7.next()){
    	    String str2=rs7.getString("name");
    	    c7 = new PdfPCell(new Phrase(str2, tablefont));  
        }
        c7.setLeading(2,(float) 1.3);
        c7.setRowspan(3); 
        c7.setColspan(3);
        c7.setBorder(2);
        c7.setMinimumHeight(30);
        c7.setHorizontalAlignment(c7.ALIGN_CENTER);
        c7.setVerticalAlignment(c7.ALIGN_MIDDLE);
        t4.addCell(c7); 
        
        c7 = new PdfPCell(new Phrase("服务电话：", tablefont));
        c7.setLeading(2,(float) 1.3);
        c7.setRowspan(3); 
        c7.setColspan(3);
        c7.setBorder(2);
        c7.setMinimumHeight(30);
        c7.setHorizontalAlignment(c7.ALIGN_CENTER);
        c7.setVerticalAlignment(c7.ALIGN_MIDDLE);
        t4.addCell(c7);

        ResultSet rs8 = stmt.executeQuery("select phone_number from user_basic_info where login_id=(select project_leader_account from contract where Id='"+contractid+"')");
        while(rs8.next()){
    	    String str2=rs8.getString("phone_number");
    	    c7 = new PdfPCell(new Phrase(str2, tablefont));  
        }
        c7.setLeading(2,(float) 1.3);
        c7.setRowspan(3); 
        c7.setColspan(3);
        c7.setBorder(2);
        c7.setMinimumHeight(30);
        c7.setHorizontalAlignment(c7.ALIGN_CENTER);
        c7.setVerticalAlignment(c7.ALIGN_MIDDLE);
        t4.addCell(c7);
        //添加页脚
        headAndFootPdfContent.saveState();
        headAndFootPdfContent.beginText();
      //设置中文
        headAndFootPdfContent.setFontAndSize(bfChinese, 8);
        //页脚信息左面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_LEFT, "项目负责人：          "+"     技术负责人：          "+"     编制人：          ", document.left() , y, 0);
        //页脚信息右面  
        headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_RIGHT, "共    页     第    页 ", document.right(), y, 0);     
        headAndFootPdfContent.endText();
        headAndFootPdfContent.restoreState();
        
        document.add(t4);
        
        document.newPage();
      //附录内容第一行
        Font titlefontzwy = new Font(bfChinese, 20, Font.NORMAL);
        Font f8 = new Font(bfChinese, 8, Font.NORMAL);
        Paragraph contenttitlezwy = new Paragraph("建筑消防设施维护保养表",titlefontzwy);
        contenttitlezwy.setAlignment(1);
        contenttitlezwy.setSpacingBefore(25);
        contenttitlezwy.setSpacingAfter(15);
        document.add(contenttitlezwy);
        
       //增加项目名称
       Font contentfontzwy = new Font(bfChinese, 14, Font.NORMAL);       
       Statement stmtzwy = DBUtil.getConnection().createStatement();
       ResultSet rszwy = stmtzwy.executeQuery("select * from first_maintenance_project as d where d.Id in (select distinct(c.Id) from first_maintenance_project as c ,"
       		+ "second_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and a.father_id=c.Id and b.contract_id='"+ contractid+"') order by d.Id");
       //select Name from first_maintenance_project  where Id=(select maintenance_id from contract_manitenance_project where contract_id="+ contractid+") order by Id"
       //select a.Name from first_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and b.contract_id='"+ contractid+"' order by a.Id"
   
      
       ArrayList<FirstMaintenance> firstMaintenance=new ArrayList<FirstMaintenance>();
       try{
    	   while(rszwy.next()){
    	    	 //  get first maintenance project item;
    	    	   FirstMaintenance fm=new FirstMaintenance();
    	    	   String strzwy=rszwy.getString("Name");
    	    	   String firstId=rszwy.getString("Id");
    	           fm.FirstMaintenanceID=firstId;
    	           fm.FisrtName=strzwy;
    	           firstMaintenance.add(fm);
    	       }
       }catch(Exception e){
			e.printStackTrace();
		}
		finally{
			try {
				rszwy.close();
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
      
       ArrayList<ArrayList<SecondMaintenance>> secondMaintenancelist=new ArrayList<ArrayList<SecondMaintenance>>();
       for(int o=0;o<firstMaintenance.size();o++){
    	   // get second maintenance project item
    	   ArrayList<SecondMaintenance> secondMaintenance=new ArrayList<SecondMaintenance>();
    	   String firstId=firstMaintenance.get(o).FirstMaintenanceID;
	       ResultSet rszwy1=stmtzwy.executeQuery("select * from second_maintenance_project as a, contract_maintenance_project as b  where a.Id=b.maintenance_id and b.contract_id='"+ contractid+"' and a.father_id='"+firstId+"' order by a.Id");
	       while(rszwy1.next()){
	    	   SecondMaintenance sm=new SecondMaintenance();
	    	   String SecondNameStr=rszwy1.getString("Name");
	    	   sm.fatherid=rszwy1.getString("father_id");
	    	   sm.Id=rszwy1.getString("Id");
	    	   sm.name=SecondNameStr;
	    	   secondMaintenance.add(sm);
	       }
	       secondMaintenancelist.add(secondMaintenance);
       }
       
      ArrayList<ArrayList<ArrayList<ThirdMaintenance>>> thirdMaintenancelistlist=new ArrayList<ArrayList<ArrayList<ThirdMaintenance>>>();
      for(int o=0;o<secondMaintenancelist.size();o++){
    	  ArrayList<ArrayList<ThirdMaintenance>> thirdMaintenancelist=new ArrayList<ArrayList<ThirdMaintenance>>();
    	  for(int p=0;p<secondMaintenancelist.get(o).size();p++){
    		  String secondid=secondMaintenancelist.get(o).get(p).Id;
    		  ArrayList<ThirdMaintenance> thirdMaintenance=new ArrayList<ThirdMaintenance>();
    		  ResultSet rszwy2=stmtzwy.executeQuery("select * from maintenance_test_content where Father_maintenance_id='"+secondid+"'");
        	  while(rszwy2.next()){
        		  ThirdMaintenance tm=new ThirdMaintenance();
        		  tm.father_maintenance_id=rszwy2.getString("Father_maintenance_id");
        		  if(rszwy2.getString("frequency")==null){
        			  tm.frequency="";
        		  }else{
        			  tm.frequency=rszwy2.getString("frequency");
        		  }
        		  tm.serial=rszwy2.getString("serial");
        		  tm.test_name=rszwy2.getString("test_name");
        		  if(rszwy2.getString("test_content")==null){
        			  tm.test_content="";
        		  }else{
        			  tm.test_content=rszwy2.getString("test_content"); 
        		  }
        		  tm.Id=rszwy2.getString("Id");
        		//  System.out.println(tm.test_name);
        		  thirdMaintenance.add(tm);
        	  }
        	  thirdMaintenancelist.add(thirdMaintenance);
    	  }
    	  thirdMaintenancelistlist.add(thirdMaintenancelist);
       }
      
      
      ArrayList<ArrayList<ArrayList<TaskItem>>> taskItemlistlist=new   ArrayList<ArrayList<ArrayList<TaskItem>>>();
      for(int o=0;o<firstMaintenance.size();o++){
    	  ArrayList<ArrayList<TaskItem>> taskItemlist=new  ArrayList<ArrayList<TaskItem>>(); 
    	  for(int p=0;p<secondMaintenancelist.get(o).size();p++){
    		  ArrayList<TaskItem> taskItem=new  ArrayList<TaskItem>(); 
    		  for(int q=0;q<thirdMaintenancelistlist.get(o).get(p).size();q++){
    			  ResultSet rszwy3=stmtzwy.executeQuery("select * from task_item where execute_time<='"+end_time+"' and execute_time>='"
    			      +start_time+"' and maintenance_detail_id='"+thirdMaintenancelistlist.get(o).get(p).get(q).Id+"' and task_id in (select t.id from building as b,task as t where b.contract_id='"
    					  +contractid+"' and t.building_id=b.id)");  
	
	    			  TaskItem ti=new TaskItem();
	    			  ti.execute_time="";
					  ti.judge_result="";
					  ti.faultDescription="";
					  ti.all_details="";
					  ti.result="";
					  while(rszwy3.next()){  
		    			  if(rszwy3.getString("maintenance_detail_id").equals(thirdMaintenancelistlist.get(o).get(p).get(q).Id)){
		    				  ti.maintenance_third_id=ti.maintenance_third_id+rszwy3.getString("maintenance_detail_id")+"; ";
		    				  ti.execute_time= ti.execute_time+rszwy3.getString("execute_time")+"; ";
		    				  if(rszwy3.getString("fault_description")==null) {
		    					  ti.faultDescription=ti.faultDescription+"";
		    				  }else{
		    					  ti.faultDescription=ti.faultDescription+rszwy3.getString("fault_description")+"; "; 
		    				  }
		  	    			  if(rszwy3.getString("judge_result")==null){
		  	    				ti.judge_result=""+ti.judge_result+""; 
		  	    			  }else{ti.judge_result=""+ti.judge_result+rszwy3.getString("judge_result")+"; ";}
		  	    			  if(rszwy3.getString("result")==null) {
		  	    				ti.result=ti.result+"";
		  	    			  }else{ti.result=ti.result+rszwy3.getString("result");}
		  	    			 if(rszwy3.getString("test_detail_string")==null||rszwy3.getString("result")==null) {
		  	    				ti.all_details=ti.all_details+"结果："+ti.result+"  "+"";
		  	    			 }else {ti.all_details=ti.all_details+"  "+ti.result+"  "+rszwy3.getString("test_detail_string")+"; ";}	  
		  	    			  ti.task_id=ti.task_id+rszwy3.getString("task_id")+"; ";
		  	    			taskItem.add(ti); 
		    			  }else{System.out.println("maintenance_detail_id !equals thirdMaintenancelistlist.k.id");}
	    			  }//end while
    			  if(ti.result.equals("")){ti.all_details="无";}
    			  taskItem.add(ti); 
    		  }// end third for 
    		  taskItemlist.add(taskItem);
    	  }// end second for
    	  taskItemlistlist.add(taskItemlist);
      }
      
      int  count=1;
      for(int o=0;o<firstMaintenance.size();o++){
    	  Paragraph contentzwy = new Paragraph(count+"."+firstMaintenance.get(o).FisrtName,contentfontzwy);    //一级维保内容
          contentzwy.setAlignment(0);
          contentzwy.setSpacingBefore(5);
          contentzwy.setSpacingAfter(5);
          contentzwy.setIndentationLeft(5);
          document.add(contentzwy); 
          
          //制作表格
          PdfPTable pdfTable1 = new PdfPTable(7);
          //设置表格占PDF文档100%宽度
          pdfTable1.setWidthPercentage(100);
          //水平方向表格控件左对齐
          pdfTable1.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
          //创建一个表格的表头单元格
          PdfPCell pdfTableHeaderCell = new PdfPCell();
          Font tablefont1=new Font(bfChinese, 10, Font.NORMAL);       
          pdfTableHeaderCell.setHorizontalAlignment(pdfTableHeaderCell.ALIGN_CENTER);
          pdfTableHeaderCell.setVerticalAlignment(pdfTableHeaderCell.ALIGN_MIDDLE);
          String[] normalTableContent={"维保项目","维保内容","测试方法和要求","实测记录","判定结果","备注","执行时间"};
          PdfPCell cell ;
          for(int tzwy=0;tzwy<7;tzwy++){
       	   cell = new PdfPCell(new Phrase(normalTableContent[tzwy].toString(),tablefont1));
       	   cell.setHorizontalAlignment(cell.ALIGN_CENTER);
       	   cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
       	   cell.setLeading(2,(float) 1.2);
       	   pdfTable1.addCell(cell);//+
          } 
//          //完成表头信息
          
          PdfPCell pdfTableContentCellzwy = new PdfPCell();
          pdfTableContentCellzwy.setHorizontalAlignment(pdfTableContentCellzwy.ALIGN_CENTER);
       //   pdfTableContentCell.setVerticalAlignment(pdfTableContentCell.ALIGN_CENTER);
          for(int p=0;p<secondMaintenancelist.get(o).size();p++){
        	  PdfPCell CellSecond=new PdfPCell(new Phrase(secondMaintenancelist.get(o).get(p).name,tablefont)) ;
        	  CellSecond.setRowspan(thirdMaintenancelistlist.get(o).get(p).size());
        	  CellSecond.setColspan(1);
        	  CellSecond.setHorizontalAlignment(CellSecond.ALIGN_CENTER);
        	  CellSecond.setVerticalAlignment(CellSecond.ALIGN_MIDDLE);
        	  CellSecond.setLeading(2,(float) 1.2);
//    	  
        	  pdfTable1.addCell(CellSecond);
        	  
        	  for(int q=0;q<thirdMaintenancelistlist.get(o).get(p).size();q++){
        		  PdfPCell Cellthird=new PdfPCell(new Phrase(thirdMaintenancelistlist.get(o).get(p).get(q).serial+"."+
        	  thirdMaintenancelistlist.get(o).get(p).get(q).test_name,tablefont));
        		  Cellthird.setHorizontalAlignment(Cellthird.ALIGN_CENTER);
        		  Cellthird.setVerticalAlignment(Cellthird.ALIGN_MIDDLE);
        		  Cellthird.setLeading(2,(float) 1.2);
        		  Cellthird.setPaddingBottom((float)2.5);
        		  
        		  PdfPCell CellDemand=new PdfPCell(new Phrase(thirdMaintenancelistlist.get(o).get(p).get(q).test_content+" "+
        				  thirdMaintenancelistlist.get(o).get(p).get(q).frequency,tablefont));
        		  CellDemand.setHorizontalAlignment(CellDemand.ALIGN_CENTER);
        		  CellDemand.setVerticalAlignment(CellDemand.ALIGN_MIDDLE);
        		  CellDemand.setLeading(2,(float) 1.2);
        		 
        		  
        		  
        		  PdfPCell Celltestlog=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).all_details,tablefont));
        		  Celltestlog.setHorizontalAlignment(Celltestlog.ALIGN_CENTER);
        		  Celltestlog.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  Celltestlog.setLeading(2,(float) 1.2);
        		 
        		  PdfPCell Celljudge=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).judge_result,tablefont)); 
        		  Celljudge.setHorizontalAlignment(Celljudge.ALIGN_CENTER);
        		  Celljudge.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  Celljudge.setLeading(2,(float) 1.2);
        		 
        		  PdfPCell CellDescription=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).faultDescription,tablefont));
        		  CellDescription.setHorizontalAlignment(CellDescription.ALIGN_CENTER);
        		  CellDescription.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  CellDescription.setLeading(2,(float) 1.2);
        		
        		  PdfPCell CellTime=new PdfPCell(new Phrase(taskItemlistlist.get(o).get(p).get(q).execute_time,tablefont));
        		  CellTime.setHorizontalAlignment(CellTime.ALIGN_CENTER);
        		  CellTime.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        		  CellTime.setLeading(2,(float) 1.2);
        		  
        		  pdfTable1.addCell(Cellthird);
        		  pdfTable1.addCell(CellDemand);
        		  pdfTable1.addCell(Celltestlog);
        		  pdfTable1.addCell(Celljudge);
        		  pdfTable1.addCell(CellDescription);
        		  pdfTable1.addCell(CellTime);
        		  

        	  }
          }
          document.add(pdfTable1);
          count++;
          //添加页脚
          headAndFootPdfContent.saveState();
          headAndFootPdfContent.beginText();
        //设置中文
          headAndFootPdfContent.setFontAndSize(bfChinese, 8);
          //页脚信息左面  
          headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_LEFT, "检测时间：        "+"项目负责人：          "+"     技术负责人：          "+"     编制人：          ", document.left() , y, 0);
          //页脚信息右面  
          headAndFootPdfContent.showTextAligned(PdfContentByte.ALIGN_RIGHT, "共    页     第    页 ", document.right(), y, 0);     
          headAndFootPdfContent.endText();
          headAndFootPdfContent.restoreState();
      }
        
//        document.close();
       return myString;
        }
	  


	  public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
	        PdfReader reader = new PdfReader(src);
	        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
	        AcroFields form = stamper.getAcroFields();
	        String[] radiostates = form.getAppearanceStates("time");
	        form.setField("time", radiostates[2]);
//	        for (int i = 0; i < TIME.length; i++) {
//	            String[] checkboxstates = form.getAppearanceStates("年");
//	            form.setField(TIME[i], checkboxstates[i % 2 == 0 ? 1 : 0]);
//	        }
	        
	        stamper.close();
	    }
	  

	  
	

}
